import { Vector3Utils } from "@sapi-game/utils";
import { WereWolfModule } from "@/werewolf/module";
import { WereWolfPlayer } from "@/werewolf/player";

export class WereWolfPlayerTeleport extends WereWolfModule.Component {
    override onAttach(): void {}

    tpAllToSpeakingLoc() {
        this.context.players.forEach((p) => this.tpToSpeakingLoc(p));
    }

    tpAllToHouse() {
        this.context.players.forEach((p) => this.tpToHouse(p));
    }

    /**传送到讲台的位置 */
    tpToSpeakingLoc(player: WereWolfPlayer) {
        if (player.no == 0) return;
        const loc = this.context.map.locations.speakingPos[player.no - 1];
        if (!loc) return;
        player.player?.teleport(Vector3Utils.fromArray(loc), {
            facingLocation: this.context.map.locations.speakingLookingPos,
        });
    }

    tpToHouse(player: WereWolfPlayer) {
        if (player.no == 0 || player.dead) return;
        const loc = this.context.map.locations.housePos[player.no - 1];
        if (!loc) return;
        player.player?.teleport(Vector3Utils.fromArray(loc));
    }
}
